using System;
using System.Windows.Forms;
using OhioState.Graphics;
using OhioState.Graphics.Proxy;

namespace OhioState.Controls
{
    public partial class CurrentColorDialog : Form
    {
        //private IAssetManagedListHandler updateEvent;
        private MaterialProxy material;

        public CurrentColorDialog()
        {
            material = null;
            InitializeComponent();
        }

        //
        // Populate dialog based on the color object given.  Use the True Color
        //  not the color with alpha values for the color dialog and the panel.
        //
        public void ShowAndInit(MaterialProxy mat)
        {
            colorPanel1.BackColor = mat.CurrentColor.TrueColor;
            colorDialog1.Color = mat.CurrentColor.TrueColor;
            material = mat;
            interactiveAlphapicker1.init(material, material.CurrentColor.A, ColorKind.CURRENT);
            this.Show();
        }

        private void colorPanel1_DoubleClick(object sender, EventArgs e)
        {
            if (material.CurrentColor != null)
            {
                colorDialog1.Color = material.CurrentColor.TrueColor;
                if (colorDialog1.ShowDialog() == DialogResult.OK)
                {
                    //
                    // Update color with the color from the dialog but preserve the alpha value
                    //
                    float alpha = material.CurrentColor.A;
                    material.BeginManipulation();
                    material.CurrentColor.Color = colorDialog1.Color;
                    material.CurrentColor.A = alpha;
                    material.EndManipulation();
                    colorPanel1.BackColor = material.CurrentColor.TrueColor;
                }
            }
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}